package test.test6_21;

import java.util.Arrays;

/*
首先准备两个数组（简单起见，用两个普通int数组即可）将这两个数组合并。
所谓合并就是将两个数组中的元素合并成一个新数组。
比如对于数组1[1,2,3]和数组2[2,2,2]
合并的结果是新数组[1,2,3,2,2,2]
 */
public class Demo01 {
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3};
        int[] arr2 = {4, 5, 6};
        int[] newArray = packedArray(arr1, arr2);
        System.out.println(Arrays.toString(newArray));
    }

    public static int[] packedArray(int[] arr1, int[] arr2) {
        int[] newArray = new int[arr1.length + arr2.length];
        for (int i = 0; i < arr1.length; i++) {
            newArray[i] = arr1[i];
        }

        for (int j = arr1.length; j < newArray.length; j++) {
            newArray[j] = arr2[j - arr1.length];
        }

        return newArray;
    }

}
